<template>
  <div class="wrapper">
    <!-- 订单操作 -->
    <div class="actions" style="margin-bottom: 10px">
      <div class="left">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleClickOperation(1)"
          >通过</el-button
        >
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleClickOperation(0)"
          >驳回</el-button
        >
      </div>
      <div class="right">
        <el-pagination
          small
          background
          :current-page="paginations.pageIndex"
          :page-sizes="paginations.pageSizes"
          :page-size="paginations.pageSize"
          :layout="paginations.layout"
          :total="paginations.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      border
      stripe
      align="center"
      @selection-change="handleSelectionChange"
      :max-height="maxheight"
    >
      <el-table-column type="selection" width="45"> </el-table-column>
      <el-table-column prop="waybill_no" label="运单号" fixed width="150">
      </el-table-column>
      <el-table-column prop="paid_money" label="退款金额" width="150">
      </el-table-column>
      <el-table-column prop="reason" label="退款原因" width="150">
      </el-table-column>
      <el-table-column prop="status" label="退款状态" width="150">
        <template slot-scope="scope">
          {{ REFUND_STATUS[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column prop="create_time" label="申请时间" width="150">
        <template slot-scope="scope">
          <span v-time="scope.row.create_time"></span>
        </template>
      </el-table-column>
      <el-table-column prop="auditor_name" label="审核人" width="150">
      </el-table-column>
      <el-table-column prop="audit_time" label="审核时间" width="150">
        <template slot-scope="scope">
          <span v-time="scope.row.audit_time"></span>
        </template>
      </el-table-column>
      <el-table-column prop="" label=""> </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="120">
        <template slot-scope="scope">
          <el-button
            type="text"
            plain
            size="mini"
            @click="handleClickOperation(2, scope.row)"
            >详情
          </el-button>
          <el-button
            type="text"
            plain
            size="mini"
            @click="handleClickOperation(3, scope.row)"
            >编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <BackMoney
      v-if="dialogVisible"
      :dialogVisible="dialogVisible"
      @close="handleCloseDialog"
      origin="review"
      :reviewType="reviewType"
      :reviewId="reviewId"
    ></BackMoney>
  </div>
</template>

<script>
import BackMoney from "@/components/backMoney/index.vue";
import { WechatpayRefundList } from "@/api/finance";
import { REFUND_STATUS } from "@/utils/constants";
export default {
  name: "refundReviewList",
  components: { BackMoney },
  props: [],
  data() {
    return {
      maxheight: "auto",
      tableData: [],
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 200,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      checkedList: [],
      searchParams: {},
      reviewType: "", //1 通过 0 驳回
      reviewId: "", //审核操作的id
      dialogVisible: false,
      REFUND_STATUS: REFUND_STATUS,
    };
  },
  mounted() {
    this.getDataList();
  },
  methods: {
    handleSelectionChange(checked) {
      this.checkedList = checked.map((item) => {
        return { id: item.id, status: item.status };
      });
    },
    // 通过、驳回
    handleClickOperation(type, row) {
      // 详情,编辑
      if (type === 2 || type === 3) {
        this.reviewId = row.id;
        // 通过,驳回
      } else {
        if (this.checkedList.length === 0) {
          this.$message({
            message: "请选中后进行操作!",
            type: "warning",
          });
          return;
        }
        if (this.checkedList.length > 1) {
          this.$message({
            message: "只支持单个操作哦!",
            type: "warning",
          });
          return;
        }
        if (
          this.checkedList[0].status !== 5 &&
          this.checkedList[0].status !== 6
        ) {
          this.$message({
            message: "当前状态暂不支持审核操作!",
            type: "warning",
          });
          return;
        }
        this.reviewId = this.checkedList[0].id;
      }
      this.reviewType = type;
      this.dialogVisible = true;
    },
    handleCloseDialog(isUpdated) {
      this.dialogVisible = false;
      if (isUpdated) {
        this.getDataList();
      }
    },
    // 每页条数改变
    handleSizeChange(val) {
      this.paginations.pageSize = val;
      this.getDataList();
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.paginations.pageIndex = val;
      this.getDataList();
    },
    getDataList() {
      WechatpayRefundList({
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        ...this.searchParams,
      }).then((res) => {
        this.tableData = res.data.data || [];
        if (this.tableData.length > 6) {
          //一排操作栏
          this.maxheight = document.documentElement.clientHeight - 245;
        } else {
          this.maxheight = "auto";
        }
        this.paginations.total = res.data.pagination.total;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  padding: 10px 15px;
  background-color: #fff;

  .orderHeader {
    margin-top: 5px;
    background-color: #fff;

    .orderSearch {
      form {
        ::v-deep .el-form-item__label {
          font-size: 14px;
        }

        .el-textarea {
          width: 135px;
        }
      }
    }
  }

  .actions {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    background-color: #fff;

    .el-button + .el-dropdown,
    .el-dropdown + .el-button {
      margin-left: 10px;
    }
  }
}
</style>